package chapter4XML;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="ShoppingConfig.xml")
public class TestShopping {
	@Autowired
	private Customer customer;
	@Autowired
	private Counter counter;
	@Test
	public void testNotNull() {
		assertNotNull(customer);
		assertNotNull(counter);
	}
	
	@Test
	public void testCounter() {
		customer.buy(1);
		customer.buy(1);
		customer.buy(2);
		customer.buy(3);
		customer.buy(3);
		customer.buy(1);
		
		counter.show();
		
		assertEquals(3, counter.getSales(1));
		assertEquals(1, counter.getSales(2));
		assertEquals(2, counter.getSales(3));
	}
}
